﻿using Device.API.Applcation.Command.EquipmentCommand;
using Device.Infrstructre.Interface;
using MediatR;

namespace Device.API.Applcation.CommandHandlers.EquipmentCommandHandlers
{
    public class BatchDelEquipmentCommandHandlers:IRequestHandler<BatchDelEquipmentCommand,int>
    {
        private readonly IEquipmentRepository _equipmentRepository;

        public BatchDelEquipmentCommandHandlers(IEquipmentRepository equipmentRepository)
        {
            _equipmentRepository = equipmentRepository;
        }

        public async Task<int> Handle(BatchDelEquipmentCommand request, CancellationToken cancellationToken)
        {
            var list =( await _equipmentRepository.GetAllAsync()).Where(x=>request.Ids.Contains(x.EquipmentId)).ToList();
            foreach (var item in list)
            {
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                item.IsDel = true;
                await _equipmentRepository.UpdateAsync(item);
            }
            return 1;
        }
    }
}
